import request from '@/router/axios'
import {
  get
} from 'js-cookie'

export function OperationLog(url) {
  return request({
    url: url,
    method: 'get',
    params: {}
  })
}
// /config/sysuploadfile/{businessId}/{businessType}
// @ApiModelProperty(value = "业务ID")
// private Integer businessId;
// @ApiModelProperty(value = "业务类型")
// private Integer businessType;
export function sysuploadfile(url) {
  return request({
    url: url,
    method: 'get',
    params: {}
  })
}
// 获取工单处理人员
export function getWorkOrderByType(id) {
  return request({
    url: '/config/csworkorderconfig/getWorkOrderByType',
    method: 'get',
    params: {
      id: id ? id : 1
    }
  })
}
//通过字典拿数据
export function getDicType(typeName) {
  return request({
    url: '/admin/dict/type/' + typeName,
    method: 'get',
    params: {}
  })
}
// 获取公司名称
export function getCompanyByPhone(obj) {
  return request({
    url: '/config/syscompany/getCompanyByPhone',
    method: 'get',
    params: obj
  })
}
// 公共导出文件
export function ExportFile(url, obj) {

  request({
    url: url,
    method: 'get',
    params: obj,
    responseType: 'blob'
  }).then(response => {
    if (!response) {
      return
    }
    let link = document.createElement('a')
    link.href = window.URL.createObjectURL(new Blob([response.data]))
    link.target = '_blank'
    let filename = response.headers['content-disposition']
    link.download = decodeURI(filename)
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
  })
}
// 导出模板
export function ExportUrlFile(url, data) {
  request({
    url: url,
    method: 'get',
    params: data
  }).then(res => {
    let link = document.createElement('a')
    link.href = res.data.data
    link.target = '_blank'
    let filename = ''
    if (url.split('/')[url.split('/').length - 1] == 0) {
      filename = '合同模板.xlsx'
    } else if (url.split('/')[url.split('/').length - 1] == 1) {
      filename = '房产模板.xlsx'
    } else if (url.split('/')[url.split('/').length - 1] == 2) {
      filename = '水电模板.xlsx'
    }
    link.download = decodeURI(filename)
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
  })
}
